home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Source / term-source.lha / Dial.c < prev    next >
C/C++ Source or Header  |  1996-10-20  |  41KB  |  1,854 lines

  1. /*
  2. **    Dial.c
  3. **
  4. **    The dialing routine as called by the phonebook
  5. **
  6. **    Copyright © 1990-1996 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. **
  9. **    :ts=4
  10. */
  11.  
  12. #ifndef _GLOBAL_H
  13. #include "Global.h"
  14. #endif
  15.  
  16.     /* Panel gadget IDs. */
  17.  
  18. enum    {    GAD_CALLING=1,GAD_TIME,GAD_NOTE,
  19.             GAD_SKIP,GAD_REMOVE,GAD_ONLINE,GAD_ABORT
  20.         };
  21.  
  22.     /* Local copy of the global serial and modem settings. */
  23.  
  24. STATIC struct SerialSettings    *OriginalSerialConfig;
  25. STATIC struct ModemSettings        *OriginalModemConfig;
  26.  
  27.     /* Local routines. */
  28.  
  29. STATIC VOID QuickHangup(struct DialNode *DialNode);
  30. STATIC VOID DialPrintBox(LayoutHandle *Handle, LONG Box, LONG Line, STRPTR String, ...);
  31. STATIC BOOL SendLocalModemCommand(LayoutHandle *Handle, STRPTR Command, STRPTR Message, STRPTR ErrorMessage);
  32. STATIC VOID BuildName(STRPTR Name, LONG MaxNameLen, STRPTR Date);
  33. STATIC VOID OpenAutoCaptureFile(STRPTR SomeName);
  34. STATIC VOID Connect(PhonebookHandle *PhoneHandle,struct DialNode *DialNode);
  35. STATIC LayoutHandle *OpenDialPanel(BOOL *Record,BOOL *SkipLoginMacro);
  36.  
  37.     /* GetCurrentSettings():
  38.      *
  39.      *    Get the settings corresponding to a dial node.*/
  40.  
  41. STATIC VOID
  42. GetCurrentSettings(struct DialNode *DialNode,struct SerialSettings **SerialPtr,struct ModemSettings **ModemPtr)
  43. {
  44.     *SerialPtr    = OriginalSerialConfig;
  45.     *ModemPtr    = OriginalModemConfig;
  46.  
  47.     if(DialNode && DialNode->Entry && DialNode->Entry->Config)
  48.     {
  49.         if(DialNode->Entry->Config->SerialConfig)
  50.             *SerialPtr = DialNode->Entry->Config->SerialConfig;
  51.  
  52.         if(DialNode->Entry->Config->ModemConfig)
  53.             *ModemPtr = DialNode->Entry->Config->ModemConfig;
  54.     }
  55. }
  56.  
  57.     /* QuickHangup(struct DialNode *DialNode):
  58.      *
  59.      *    Stop dialing by hanging up or sending a return character to the modem.
  60.      */
  61.  
  62. STATIC VOID
  63. QuickHangup(struct DialNode *DialNode)
  64. {
  65.     BOOL UseHangUp;
  66.  
  67.     if(DialNode->Entry && DialNode->Entry->Config->ModemConfig)
  68.         UseHangUp = DialNode->Entry->Config->ModemConfig->AbortHangsUp;
  69.     else
  70.         UseHangUp = OriginalModemConfig->AbortHangsUp;
  71.  
  72.     if(UseHangUp)
  73.         HangUp();
  74.     else
  75.     {
  76.         SerWrite("\r",1);
  77.  
  78.         StartTime(1,0);
  79.  
  80.             /* Wait for the modem to respond or the timer to elapse. */
  81.  
  82.         Wait(GetJobMask(SerialJob) | SIG_TIMER);
  83.  
  84.         StopTime();
  85.     }
  86.  
  87.         /* Ignore the response of the modem. */
  88.  
  89.     while(RunJob(SerialJob));
  90.  
  91.     ResetDataFlowFilter();
  92. }
  93.  
  94.     /* DialPrintBox():
  95.      *
  96.      *    Render text into one of the display box lines.
  97.      */
  98.  
  99. STATIC VOID
  100. DialPrintBox(LayoutHandle *Handle,LONG Box,LONG Line,STRPTR String,...)
  101. {
  102.     UBYTE LocalBuffer[256];
  103.     va_list VarArgs;
  104.  
  105.     va_start(VarArgs,String);
  106.     LimitedVSPrintf(sizeof(LocalBuffer),LocalBuffer,String,VarArgs);
  107.     va_end(VarArgs);
  108.  
  109.     LT_SetAttributes(Handle,Box,
  110.         LABX_Index,    Line,
  111.         LABX_Text,    LocalBuffer,
  112.     TAG_DONE);
  113. }
  114.  
  115.     /* SendModemCommandGetResponse(LayoutHandle *Handle,STRPTR Command):
  116.      *
  117.      *    Send a modem command and wait for a response.
  118.      */
  119.  
  120. STATIC BOOL
  121. SendModemCommandGetResponse(LayoutHandle *Handle,STRPTR Command)
  122. {
  123.     ULONG Signals,SerialMask,WindowMask;
  124.     ULONG LastBytesOut;
  125.     BOOL Done;
  126.  
  127.         /* Reset the data flow scanner. */
  128.  
  129.     ResetDataFlowFilter();
  130.  
  131.         /* Send the modem command, but first remember how many
  132.          * bytes were sent yet.
  133.          */
  134.  
  135.     LastBytesOut = BytesOut;
  136.  
  137.     SerialCommand(Command);
  138.  
  139.         /* If no serial output took place, we'll return
  140.          * immediately.
  141.          */
  142.  
  143.     if(BytesOut == LastBytesOut)
  144.         return(TRUE);
  145.  
  146.         /* Get the two wait masks. */
  147.  
  148.     SerialMask = GetJobMask(SerialJob);
  149.     WindowMask = PORTMASK(Handle->Window->UserPort);
  150.  
  151.         /* Start the timer. We will wait up to ten seconds for
  152.          * the modem to respond.
  153.          */
  154.  
  155.     StartTime(10,0);
  156.  
  157.     Done = FALSE;
  158.  
  159.     do
  160.     {
  161.             /* Wait for something to happen. */
  162.  
  163.         Signals = Wait(SerialMask | WindowMask | SIG_TIMER);
  164.  
  165.             /* Any window signal? */
  166.  
  167.         if(Signals & WindowMask)
  168.         {
  169.             struct IntuiMessage    *Message;
  170.             ULONG MsgClass,MsgQualifier;
  171.             struct Gadget *MsgGadget;
  172.             UWORD MsgCode;
  173.  
  174.                 /* Check if we are to skip or abort. */
  175.  
  176.             while(Message = LT_GetIMsg(Handle))
  177.             {
  178.                 MsgClass        = Message->Class;
  179.                 MsgCode            = Message->Code;
  180.                 MsgQualifier    = Message->Qualifier;
  181.                 MsgGadget        = Message->IAddress;
  182.  
  183.                 LT_ReplyIMsg(Message);
  184.  
  185.                     /* Convert the space keypress into a
  186.                      * skip command.
  187.                      */
  188.  
  189.                 if(MsgClass == IDCMP_RAWKEY)
  190.                 {
  191.                     if(LT_GetCode(MsgQualifier,MsgClass,MsgCode,MsgGadget) == ' ')
  192.                         Done = TRUE;
  193.                 }
  194.  
  195.                     /* So a button was pressed. */
  196.  
  197.                 if(MsgClass == IDCMP_GADGETUP)
  198.                 {
  199.                     switch(MsgGadget->GadgetID)
  200.                     {
  201.                         case GAD_SKIP:
  202.                         case GAD_ABORT:
  203.  
  204.                             Done = TRUE;
  205.                             break;
  206.                     }
  207.                 }
  208.             }
  209.         }
  210.  
  211.             /* Any modem signal? */
  212.  
  213.         if(Signals & SerialMask)
  214.         {
  215.                 /* Handle the serial input. */
  216.  
  217.             while(RunJob(SerialJob));
  218.  
  219.                 /* Exit if the modem said something sensible. */
  220.  
  221.             if(FlowInfo.Changed)
  222.                 Done = TRUE;
  223.         }
  224.  
  225.             /* Did the bell ring? */
  226.  
  227.         if(Signals & SIG_TIMER)
  228.             Done = TRUE;
  229.     }
  230.     while(!Done);
  231.  
  232.         /* Stop the timer. */
  233.  
  234.     StopTime();
  235.  
  236.         /* Did the modem respond? */
  237.  
  238.     return(FlowInfo.Changed);
  239. }
  240.  
  241.     /* SendLocalModemCommand():
  242.      *
  243.      *    Send a command to the modem and display an error message if necessary.
  244.      */
  245.  
  246. STATIC BOOL
  247. SendLocalModemCommand(LayoutHandle *Handle,STRPTR Command,STRPTR Message,STRPTR ErrorMessage)
  248. {
  249.         /* Show the message. */
  250.  
  251.     DialPrintBox(Handle,GAD_NOTE,0,Message);
  252.  
  253.         /* Send the command and check if the modem did respond. */
  254.  
  255.     if(SendModemCommandGetResponse(Handle,Command))
  256.     {
  257.             /* No news is good news. */
  258.  
  259.         if(!FlowInfo.Error)
  260.             return(TRUE);
  261.         else
  262.             DialPrintBox(Handle,GAD_NOTE,0,ErrorMessage);
  263.     }
  264.     else
  265.         DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_MODEM_NOT_RESPONDING_TXT));
  266.  
  267.     WakeUp(Handle->Window,SOUND_ERROR);
  268.     return(FALSE);
  269. }
  270.  
  271.     /* BuildName(STRPTR Name):
  272.      *
  273.      *    Build a file name from a BBS name and the current date.
  274.      */
  275.  
  276. STATIC VOID
  277. BuildName(STRPTR Name,LONG MaxNameLen,STRPTR Date)
  278. {
  279.     if(Date[0])
  280.     {
  281.         LONG NameLen,DateLen,Delta;
  282.  
  283.         NameLen = strlen(Name);
  284.         DateLen = strlen(Date);
  285.  
  286.         if((Delta = NameLen + 1 + DateLen - 32) > 0)
  287.             Name[NameLen - Delta] = 0;
  288.  
  289.         LimitedStrcat(MaxNameLen,Name,"_");
  290.         LimitedStrcat(MaxNameLen,Name,Date);
  291.     }
  292. }
  293.  
  294.     /* OpenAutoCaptureFile(STRPTR SomeName):
  295.      *
  296.      *    Open a capture file.
  297.      */
  298.  
  299. STATIC VOID
  300. OpenAutoCaptureFile(STRPTR SomeName)
  301. {
  302.     struct DateTime    DateTime;
  303.     UBYTE Date[20],Time[20];
  304.  
  305.         /* Get the current time and date. */
  306.  
  307.     DateStamp(&DateTime.dat_Stamp);
  308.  
  309.         /* Prepare for date conversion. */
  310.  
  311.     DateTime.dat_Format        = FORMAT_DEF;
  312.     DateTime.dat_Flags        = 0;
  313.     DateTime.dat_StrDay        = NULL;
  314.     DateTime.dat_StrDate    = Date;
  315.     DateTime.dat_StrTime    = Time;
  316.  
  317.         /* Convert the date. */
  318.  
  319.     if(DateToStr(&DateTime))
  320.     {
  321.         UBYTE LocalBuffer[MAX_FILENAME_LENGTH],Name[MAX_FILENAME_LENGTH];
  322.  
  323.             /* Remember the BBS name. */
  324.  
  325.         LimitedStrcpy(sizeof(Name),Name,SomeName);
  326.  
  327.             /* Append the creation date if necessary. */
  328.  
  329.         if(Config->CaptureConfig->AutoCaptureDate == AUTOCAPTURE_DATE_NAME)
  330.             BuildName(Name,sizeof(Name),Date);
  331.  
  332.             /* Make it a reasonable name. */
  333.  
  334.         FixName(Name);
  335.  
  336.             /* Get the capture file path. */
  337.  
  338.         LimitedStrcpy(sizeof(LocalBuffer),LocalBuffer,Config->CaptureConfig->CapturePath);
  339.  
  340.             /* Try to build a valid file and path name. */
  341.  
  342.         if(AddPart(LocalBuffer,Name,sizeof(LocalBuffer)))
  343.         {
  344.                 /* Is the capture file still open? */
  345.  
  346.             if(FileCapture)
  347.             {
  348.                     /* Close the file. */
  349.  
  350.                 BufferClose(FileCapture);
  351.  
  352.                 FileCapture = NULL;
  353.  
  354.                     /* Any data written? */
  355.  
  356.                 if(!GetFileSize(CaptureName))
  357.                     DeleteFile(CaptureName);
  358.                 else
  359.                 {
  360.                     AddProtection(CaptureName,FIBF_EXECUTE);
  361.  
  362.                     if(Config->MiscConfig->CreateIcons)
  363.                         AddIcon(CaptureName,FILETYPE_TEXT,TRUE);
  364.                 }
  365.             }
  366.  
  367.                 /* Try to append the new data. */
  368.  
  369.             if(FileCapture = BufferOpen(LocalBuffer,"a"))
  370.             {
  371.                     /* Set the menu checkmark. */
  372.  
  373.                 CheckItem(MEN_CAPTURE_TO_FILE,TRUE);
  374.  
  375.                     /* Remember the current capture file name. */
  376.  
  377.                 strcpy(CaptureName,LocalBuffer);
  378.  
  379.                     /* Add the creation date if necessary. */
  380.  
  381.                 if(Config->CaptureConfig->AutoCaptureDate == AUTOCAPTURE_DATE_INCLUDE)
  382.                 {
  383.                     UBYTE DateTimeBuffer[256];
  384.  
  385.                     if(FormatStamp(&DateTime.dat_Stamp,DateTimeBuffer,sizeof(DateTimeBuffer),FALSE))
  386.                         BPrintf(FileCapture,LocaleString(MSG_DIALPANEL_FILE_CREATED_TXT),DateTimeBuffer);
  387.                 }
  388.             }
  389.             else
  390.                 CheckItem(MEN_CAPTURE_TO_FILE,FALSE);
  391.  
  392.             ConOutputUpdate();
  393.         }
  394.     }
  395. }
  396.  
  397.     /* Connect(PhonebookHandle *PhoneHandle,struct DialNode *DialNode):
  398.      *
  399.      *    Perform connect action(s).
  400.      */
  401.  
  402. STATIC VOID
  403. Connect(PhonebookHandle *PhoneHandle,struct DialNode *DialNode)
  404. {
  405.     struct ModemSettings *ModemConfig;
  406.     ULONG RateIs;
  407.     STRPTR Name;
  408.  
  409.         /* Check which modem configuration to use later. */
  410.  
  411.     if(DialNode->Entry && DialNode->Entry->Config->ModemConfig)
  412.         ModemConfig = DialNode->Entry->Config->ModemConfig;
  413.     else
  414.         ModemConfig = OriginalModemConfig;
  415.  
  416.         /* Get the current area code settings. */
  417.  
  418.     SetActivePattern(FindTimeDate(PatternList,DialNode->Number));
  419.  
  420.         /* Mark the active phonebook entry, if any. */
  421.  
  422.     SetActiveEntry(PhoneHandle,DialNode->Entry);
  423.  
  424.         /* Get the DTE rate ready. */
  425.  
  426.     if(DTERate > 0)
  427.         RateIs = DTERate;
  428.     else
  429.         RateIs = Config->SerialConfig->BaudRate;
  430.  
  431.         /* Does the node have a phonebook entry attached? */
  432.  
  433.     if(DialNode->Entry)
  434.     {
  435.         SaveConfig(DialNode->Entry->Config,Config);
  436.         ConfigChanged = FALSE;
  437.  
  438.         Name = DialNode->Entry->Header->Name;
  439.  
  440.         strcpy(Password,DialNode->Entry->Header->Password);
  441.         strcpy(UserName,DialNode->Entry->Header->UserName);
  442.  
  443.         SendStartup = TRUE;
  444.  
  445.         strcpy(CurrentBBSName,DialNode->Entry->Header->Name);
  446.         strcpy(CurrentBBSComment,DialNode->Entry->Header->Comment);
  447.  
  448.         LogAction(LocaleString(MSG_DIALPANEL_CONNECTED_TO_1_TXT),Name,DialNode->Number,RateIs);
  449.     }
  450.     else
  451.     {
  452.         Name = LocaleString(MSG_GLOBAL_UNKNOWN_TXT);
  453.  
  454.         Password[0]    = 0;
  455.         UserName[0]    = 0;
  456.  
  457.         SendStartup    = FALSE;
  458.  
  459.         CurrentBBSName[0]        = 0;
  460.         CurrentBBSComment[0]    = 0;
  461.  
  462.         LogAction(LocaleString(MSG_DIALPANEL_CONNECTED_TO_2_TXT),DialNode->Number,RateIs);
  463.     }
  464.  
  465.         /* Register the call. */
  466.  
  467.     MakeCall(Name,DialNode->Number);
  468.  
  469.         /* Store the current phone number. */
  470.  
  471.     strcpy(CurrentBBSNumber,DialNode->Number);
  472.  
  473.         /* Get the online time limit and the macro to execute when the limit is reached. */
  474.  
  475.     if(ModemConfig->ConnectLimit > 0 && ModemConfig->ConnectLimitMacro[0])
  476.     {
  477.         ArmLimit(ModemConfig->ConnectLimit);
  478.  
  479.         strcpy(LimitMacro,ModemConfig->ConnectLimitMacro);
  480.     }
  481.     else
  482.         DisarmLimit();
  483.  
  484.         /* We are now online. */
  485.  
  486.     SetOnlineState(TRUE);
  487.  
  488.         /* Start the accounting process */
  489.  
  490.     StartAccountant(ModemConfig->TimeToConnect);
  491.  
  492.         /* Open auto-capture file. */
  493.  
  494.     if(Config->CaptureConfig->ConnectAutoCapture && Config->CaptureConfig->CapturePath[0])
  495.     {
  496.         STRPTR FileName;
  497.  
  498.         if(DialNode->Entry)
  499.             FileName = DialNode->Entry->Header->Name;
  500.         else
  501.             FileName = LocaleString(MSG_DIALPANEL_CAPTURE_NAME_TXT);
  502.  
  503.         OpenAutoCaptureFile(FileName);
  504.     }
  505.  
  506.         /* Remove node from dialing list and perform system setup. */
  507.  
  508.     RemoveAndDeleteRelatedDialNodes(PhoneHandle,DialNode);
  509.  
  510.         /* Make a backup of the old settings. */
  511.  
  512.     if(PrivateConfig->MiscConfig->BackupConfig && !BackupConfig)
  513.     {
  514.         if(BackupConfig = CreateConfiguration(TRUE))
  515.             SaveConfig(PrivateConfig,BackupConfig);
  516.     }
  517.  
  518.         /* Make sure that the following
  519.          * setup/initialization will not
  520.          * touch the serial configuration.
  521.          */
  522.  
  523.     PutConfigEntry(PrivateConfig,Config->SerialConfig,PREF_SERIAL);
  524.  
  525.     ConfigSetup();
  526.  
  527.         /* Reset the scanner. */
  528.  
  529.     ResetDataFlowFilter();
  530. }
  531.  
  532.     /* OpenDialPanel(BOOL *Record):
  533.      *
  534.      *    Open the dialing panel.
  535.      */
  536.  
  537. STATIC LayoutHandle *
  538. OpenDialPanel(BOOL *Record,BOOL *SkipLoginMacro)
  539. {
  540.     LayoutHandle *Handle;
  541.  
  542.     if(Handle = LT_CreateHandleTags(Window->WScreen,
  543.         LAHN_LocaleHook,    &LocaleHook,
  544.     TAG_DONE))
  545.     {
  546.         LT_New(Handle,
  547.             LA_Type,    VERTICAL_KIND,
  548.         TAG_DONE);
  549.         {
  550.             LT_New(Handle,
  551.                 LA_Type,    VERTICAL_KIND,
  552.             TAG_DONE);
  553.             {
  554.                 LT_New(Handle,
  555.                     LA_Type,    VERTICAL_KIND,
  556.                 TAG_DONE);
  557.                 {
  558.                     LT_New(Handle,
  559.                         LA_Type,            BOX_KIND,
  560.                         LA_ID,                GAD_CALLING,
  561.                         LA_Chars,            40,
  562.                         LABX_Rows,            4,
  563.                         LABX_ReserveSpace,    TRUE,
  564.                         LABX_FirstLabel,    MSG_DIALPANEL_CALLING_TXT,
  565.                         LABX_LastLabel,        MSG_DIALPANEL_NEXT_TXT,
  566.                     TAG_DONE);
  567.  
  568.                     LT_New(Handle,
  569.                         LA_Type,            BOX_KIND,
  570.                         LA_ID,                GAD_TIME,
  571.                         LABX_Rows,            2,
  572.                         LABX_ReserveSpace,    TRUE,
  573.                         LABX_FirstLabel,    MSG_DIALPANEL_TIMEOUT_TXT,
  574.                         LABX_LastLabel,        MSG_DIALPANEL_ATTEMPT_TXT,
  575.                     TAG_DONE);
  576.  
  577.                     LT_New(Handle,
  578.                         LA_Type,            BOX_KIND,
  579.                         LA_ID,                GAD_NOTE,
  580.                         LABX_Rows,            1,
  581.                         LABX_ReserveSpace,    TRUE,
  582.                         LABX_FirstLabel,    MSG_DIALPANEL_MESSAGE_TXT,
  583.                         LABX_LastLabel,        MSG_DIALPANEL_MESSAGE_TXT,
  584.                     TAG_DONE);
  585.  
  586.                     LT_EndGroup(Handle);
  587.                 }
  588.  
  589.                 LT_New(Handle,
  590.                     LA_Type,    VERTICAL_KIND,
  591.                 TAG_DONE);
  592.                 {
  593.                     LT_New(Handle,
  594.                         LA_Type,        XBAR_KIND,
  595.                     TAG_DONE);
  596.  
  597.                     LT_New(Handle,
  598.                         LA_Type,        CHECKBOX_KIND,
  599.                         LA_LabelID,        MSG_DIALPANEL_RECORD_ON_CONNECTION_TXT,
  600.                         LA_BOOL,        Record,
  601.                     TAG_DONE);
  602.  
  603.                     LT_New(Handle,
  604.                         LA_Type,        CHECKBOX_KIND,
  605.                         LA_LabelID,        MSG_SKIP_LOGIN_MACRO_GAD,
  606.                         LA_BOOL,        SkipLoginMacro,
  607.                     TAG_DONE);
  608.  
  609.                     LT_EndGroup(Handle);
  610.                 }
  611.  
  612.                 LT_EndGroup(Handle);
  613.             }
  614.  
  615.             LT_New(Handle,
  616.                 LA_Type,VERTICAL_KIND,
  617.             TAG_DONE);
  618.             {
  619.                 LT_New(Handle,
  620.                     LA_Type,        XBAR_KIND,
  621.                     LAXB_FullSize,    TRUE,
  622.                 TAG_DONE);
  623.  
  624.                 LT_EndGroup(Handle);
  625.             }
  626.  
  627.             LT_New(Handle,LA_Type,HORIZONTAL_KIND,
  628.                 LAGR_Spread,    TRUE,
  629.             TAG_DONE);
  630.             {
  631.                 LT_New(Handle,
  632.                     LA_Type,        BUTTON_KIND,
  633.                     LA_LabelID,        MSG_DIALPANEL_SKIP_GAD,
  634.                     LA_ID,            GAD_SKIP,
  635.                     LABT_ExtraFat,    TRUE,
  636.                     GA_Disabled,    TRUE,
  637.                 TAG_DONE);
  638.  
  639.                 LT_New(Handle,
  640.                     LA_Type,        BUTTON_KIND,
  641.                     LA_LabelID,        MSG_GLOBAL_REMOVE_GAD,
  642.                     LA_ID,            GAD_REMOVE,
  643.                     LABT_ExtraFat,    TRUE,
  644.                     GA_Disabled,    TRUE,
  645.                 TAG_DONE);
  646.  
  647.                 LT_New(Handle,
  648.                     LA_Type,        BUTTON_KIND,
  649.                     LA_LabelID,        MSG_DIALPANEL_GO_TO_ONLINE_GAD,
  650.                     LA_ID,            GAD_ONLINE,
  651.                     LABT_ReturnKey,    TRUE,
  652.                     LABT_ExtraFat,    TRUE,
  653.                 TAG_DONE);
  654.  
  655.                 LT_New(Handle,
  656.                     LA_Type,        BUTTON_KIND,
  657.                     LA_LabelID,        MSG_GLOBAL_ABORT_GAD,
  658.                     LA_ID,            GAD_ABORT,
  659.                     LABT_ExtraFat,    TRUE,
  660.                 TAG_DONE);
  661.  
  662.                 LT_EndGroup(Handle);
  663.             }
  664.  
  665.             LT_EndGroup(Handle);
  666.         }
  667.  
  668.         if(LT_Build(Handle,
  669.             LAWN_TitleID,        MSG_DIALPANEL_DIALING_TXT,
  670.             LAWN_IDCMP,            IDCMP_CLOSEWINDOW,
  671.             LAWN_HelpHook,        &GuideHook,
  672.             LAWN_Parent,        Window,
  673.             WA_DepthGadget,        TRUE,
  674.             WA_CloseGadget,        TRUE,
  675.             WA_DragBar,            TRUE,
  676.             WA_RMBTrap,            TRUE,
  677.             WA_Activate,        TRUE,
  678.         /*    WA_SimpleRefresh,    TRUE, */
  679.         TAG_DONE))
  680.             return(Handle);
  681.         else
  682.             LT_DeleteHandle(Handle);
  683.     }
  684.  
  685.     return(NULL);
  686. }
  687.  
  688.     /* DialPanel():
  689.      *
  690.      *    This routine opens a small window in the middle of the
  691.      *    console window and walks down the list of numbers to
  692.      *    dial.
  693.      */
  694.  
  695. BOOL
  696. DialPanel(PhonebookHandle *PhoneHandle)
  697. {
  698.     enum { STOP_Not,STOP_Abort,STOP_Skip };
  699.     enum { START_Dial,START_Call,START_Wait };
  700.  
  701.     BOOL ReturnToPhonebook,RecordOnConnection,ReleaseSerialDevice,SkipLoginMacro;
  702.     LayoutHandle *Handle;
  703.  
  704.             /* Remember the original modem and serial settings, so we
  705.              * can return to them later.
  706.              */
  707.  
  708.     OriginalSerialConfig    = CreateNewConfigEntry(PREF_SERIAL);
  709.     OriginalModemConfig        = CreateNewConfigEntry(PREF_MODEM);
  710.  
  711.     if(!OriginalSerialConfig || !OriginalModemConfig)
  712.     {
  713.         FreeVecPooled(OriginalSerialConfig);
  714.         OriginalSerialConfig = NULL;
  715.  
  716.         FreeVecPooled(OriginalModemConfig);
  717.         OriginalModemConfig = NULL;
  718.  
  719.         DisplayBeep(NULL);
  720.  
  721.         return(FALSE);
  722.     }
  723.  
  724.     ReturnToPhonebook = RecordOnConnection = ReleaseSerialDevice = SkipLoginMacro = FALSE;
  725.  
  726.     if(Handle = OpenDialPanel(&RecordOnConnection,&SkipLoginMacro))
  727.     {
  728.         struct SerialSettings *    CurrentSerialConfig;
  729.         struct ModemSettings *    CurrentModemConfig;
  730.  
  731.         struct Window *            PanelWindow;
  732.  
  733.         UBYTE                    NoteText[80];
  734.  
  735.         UBYTE                    ExitCommand[80];
  736.  
  737.         UBYTE                    ExitBuffer[80],
  738.                                  InitBuffer[80];
  739.  
  740.         UBYTE                     PrefixBuffer[80],
  741.                                  SuffixBuffer[80];
  742.  
  743.         UBYTE                    DialBuffer[300];
  744.  
  745.         LONG                    DialTimeout,DialRetries,DialAttempt;
  746.  
  747.         struct DialNode *        DialNode;
  748.  
  749.         LONG                    RedialTimeout;
  750.  
  751.         WORD                    Start,Stop;
  752.  
  753.         BOOL                    DoNotHangUp,ErrorHasOccured,ModemNotResponding,Done;
  754.  
  755.         BOOL                    OldQuietSettings;
  756.  
  757.         ULONG                    ODUMask,WindowMask,Signals;
  758.  
  759.         SENDLINE                OriginalSendLine;
  760.  
  761.         struct timeval            LastTimeCheck;
  762.  
  763.             /* Start from scratch. */
  764.  
  765.         PanelWindow         = Handle->Window;
  766.  
  767.         DialRetries            = 0;
  768.         DialAttempt            = 0;
  769.         DialNode            = NULL;
  770.  
  771.         ErrorHasOccured        = FALSE;
  772.         ModemNotResponding    = FALSE;
  773.         DoNotHangUp         = FALSE;
  774.  
  775.         Done                = FALSE;
  776.  
  777.         Start                = START_Call;
  778.         Stop                = STOP_Not;
  779.  
  780.         GetCurrentSettings(NULL,&CurrentSerialConfig,&CurrentModemConfig);
  781.  
  782.         GetSysTime(&LastTimeCheck);
  783.  
  784.             /* Don't mix up the line send stuff with the default sending routine */
  785.  
  786.         OriginalSendLine = ChangeSendLine(SendLineDial);
  787.  
  788.             /* Set up the ODU stuff */
  789.  
  790.         if(OwnDevUnitBase && Config->SerialConfig->ReleaseODUWhenDialing && Config->SerialConfig->SatisfyODURequests != ODU_KEEP && !(Config->SerialConfig->Shared && Config->SerialConfig->NoODUIfShared))
  791.             ODUMask = SIG_OWNDEVUNIT;
  792.         else
  793.             ODUMask = NULL;
  794.  
  795.             /* And get the window port mask ready */
  796.  
  797.         WindowMask = PORTMASK(Handle->Window->UserPort);
  798.  
  799.             /* Reset the area code scanner data. */
  800.  
  801.         SetActivePattern(NULL);
  802.         SetActiveEntry(PhoneHandle,NULL);
  803.  
  804.             /* We are now dialing. */
  805.  
  806.         PushStatus(STATUS_DIALING);
  807.  
  808.             /* Set up the AmigaGuide help context. */
  809.  
  810.         GuideContext(CONTEXT_DIAL);
  811.  
  812.             /* No exit command is defined yet. */
  813.  
  814.         ExitCommand[0] = 0;
  815.  
  816.             /* Make the current one the active one. */
  817.  
  818.         LT_ShowWindow(Handle,TRUE);
  819.  
  820.         PushWindow(PanelWindow);
  821.  
  822.             /* Make a backup of the current configuration. */
  823.  
  824.         SaveConfig(Config,PrivateConfig);
  825.  
  826.             /* Don't echo serial output unless requested by the user. */
  827.  
  828.         OldQuietSettings = SetConsoleQuiet((BOOL)(Config->ModemConfig->VerboseDialing == FALSE));
  829.  
  830.             /* Reset the scanner. */
  831.  
  832.         ResetDataFlowFilter();
  833.  
  834.             /* Get the entry signals ready and clear those we do not yet care about. */
  835.  
  836.         Signals = SetSignal(0,SIG_BREAK | SIG_SKIP | ODUMask | WindowMask) & (ODUMask | WindowMask);
  837.  
  838.             /* The big dialing loop. */
  839.  
  840.         do
  841.         {
  842.                 /* Abort the process? */
  843.  
  844.             if(!Done && (Signals & SIG_BREAK))
  845.             {
  846.                 Stop = STOP_Abort;
  847.                 Done = TRUE;
  848.             }
  849.  
  850.                 /* Check if we should let go of the device */
  851.  
  852.             if(!Done && (Signals & ODUMask))
  853.             {
  854.                 Stop = STOP_Abort;
  855.                 Done = TRUE;
  856.  
  857.                 ReleaseSerialDevice = TRUE;
  858.             }
  859.  
  860.                 /* Any window input? */
  861.  
  862.             if(!Done && (Signals & WindowMask))
  863.             {
  864.                 struct IntuiMessage    *Message;
  865.                 ULONG MsgClass,MsgQualifier;
  866.                 struct Gadget *MsgGadget;
  867.                 UWORD MsgCode;
  868.  
  869.                 while(Message = LT_GetIMsg(Handle))
  870.                 {
  871.                     MsgClass        = Message->Class;
  872.                     MsgCode            = Message->Code;
  873.                     MsgQualifier    = Message->Qualifier;
  874.                     MsgGadget        = Message->IAddress;
  875.  
  876.                     LT_ReplyIMsg(Message);
  877.  
  878.                         /* Convert the space keypress into a
  879.                          * skip command.
  880.                          */
  881.  
  882.                     if(MsgClass == IDCMP_RAWKEY)
  883.                     {
  884.                         if(LT_GetCode(MsgQualifier,MsgClass,MsgCode,MsgGadget) == ' ')
  885.                         {
  886.                             if(Stop == STOP_Not && Start != START_Call)
  887.                             {
  888.                                 LT_PressButton(Handle,GAD_SKIP);
  889.  
  890.                                 Stop = STOP_Skip;
  891.                             }
  892.                         }
  893.                     }
  894.  
  895.                         /* Close the window, hang up the line,
  896.                          * return to the phone book.
  897.                          */
  898.  
  899.                     if(MsgClass == IDCMP_CLOSEWINDOW)
  900.                     {
  901.                         Stop = STOP_Abort;
  902.                         Done = TRUE;
  903.                         ReturnToPhonebook = TRUE;
  904.                     }
  905.  
  906.                         /* So a button was pressed. */
  907.  
  908.                     if(MsgClass == IDCMP_GADGETUP)
  909.                     {
  910.                         switch(MsgGadget->GadgetID)
  911.                         {
  912.                                 /* Remove the currently active dialing
  913.                                  * list entry.
  914.                                  */
  915.  
  916.                             case GAD_REMOVE:
  917.  
  918.                                     /* This makes sense only while
  919.                                      * we are dialing.
  920.                                      */
  921.  
  922.                                 if(Start == START_Dial)
  923.                                 {
  924.                                     struct DialNode    *NextNode;
  925.  
  926.                                     NextNode = NULL;
  927.  
  928.                                         /* If still dialing, hang up first. */
  929.  
  930.                                     if(DoNotHangUp)
  931.                                         DoNotHangUp = FALSE;
  932.                                     else
  933.                                         QuickHangup(DialNode);
  934.  
  935.                                         /* Is there another entry in the list? */
  936.  
  937.                                     if(DialNode->Node.ln_Succ->ln_Succ)
  938.                                         NextNode = (struct DialNode *)DialNode->Node.ln_Succ;
  939.                                     else
  940.                                     {
  941.                                             /* No, there isn't; do we have a list with
  942.                                              * at least two entries in it?
  943.                                              */
  944.  
  945.                                         if(PhoneHandle->DialList->lh_Head->ln_Succ->ln_Succ)
  946.                                         {
  947.                                                 /* Yet another dialing attempt coming up... */
  948.  
  949.                                             DialAttempt++;
  950.  
  951.                                                 /* Check for dial retry limit. */
  952.  
  953.                                             if(DialRetries >= 0 && DialAttempt >= DialRetries)
  954.                                             {
  955.                                                 DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_MAXIMUM_NUMBER_OF_DIAL_RETRIES_TXT));
  956.  
  957.                                                 WakeUp(PanelWindow,SOUND_BELL);
  958.  
  959.                                                 DelayTime(2,0);
  960.  
  961.                                                 Say(LocaleString(MSG_DIALPANEL_MAXIMUM_NUMBER_OF_DIAL_RETRIES_TXT));
  962.  
  963.                                                 Done = TRUE;
  964.                                             }
  965.                                             else
  966.                                             {
  967.                                                     /* Grab first list entry and continue. */
  968.  
  969.                                                 NextNode = (struct DialNode *)PhoneHandle->DialList->lh_Head;
  970.                                             }
  971.                                         }
  972.                                         else
  973.                                         {
  974.                                                 /* That's all, folks! */
  975.  
  976.                                             DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_DIALING_LIST_IS_EMPTY_TXT));
  977.  
  978.                                             DelayTime(2,0);
  979.  
  980.                                             Done = TRUE;
  981.                                         }
  982.                                     }
  983.  
  984.                                         /* Remove dial entry from list. */
  985.  
  986.                                     RemoveDialNode(PhoneHandle,DialNode);
  987.                                     DeleteDialNode(DialNode);
  988.  
  989.                                         /* Is there an entry to proceed with? */
  990.  
  991.                                     if(DialNode = NextNode)
  992.                                         Start = START_Call;
  993.  
  994.                                     GetCurrentSettings(DialNode,&CurrentSerialConfig,&CurrentModemConfig);
  995.                                 }
  996.  
  997.                                 break;
  998.  
  999.                             case GAD_SKIP:
  1000.  
  1001.                                 if(Stop == STOP_Not && Start != START_Call)
  1002.                                     Stop = STOP_Skip;
  1003.  
  1004.                                 break;
  1005.  
  1006.                             case GAD_ONLINE:
  1007.  
  1008.                                     /* Go online so soon? */
  1009.  
  1010.                                 if(!DialNode)
  1011.                                 {
  1012.                                     if(!IsListEmpty(PhoneHandle->DialList))
  1013.                                         DialNode = (struct DialNode *)PhoneHandle->DialList->lh_Head;
  1014.                                 }
  1015.  
  1016.                                 if(DialNode)
  1017.                                     Connect(PhoneHandle,DialNode);
  1018.  
  1019.                                 GetCurrentSettings(DialNode,&CurrentSerialConfig,&CurrentModemConfig);
  1020.  
  1021.                                 Done = TRUE;
  1022.  
  1023.                                 break;
  1024.  
  1025.                                 /* Abort the dialing process. */
  1026.  
  1027.                             case GAD_ABORT:
  1028.  
  1029.                                 Stop = STOP_Abort;
  1030.                                 Done = TRUE;
  1031.  
  1032.                                 break;
  1033.                         }
  1034.                     }
  1035.  
  1036.                     if(Done)
  1037.                         break;
  1038.                 }
  1039.             }
  1040.  
  1041.                 /* Skip the current action? */
  1042.  
  1043.             if(!Done && (Signals & SIG_SKIP))
  1044.             {
  1045.                 if(Stop == STOP_Not && Start != START_Call)
  1046.                     Stop = STOP_Skip;
  1047.             }
  1048.  
  1049.                 /* Are we to abort? */
  1050.  
  1051.             if(Stop == STOP_Abort)
  1052.             {
  1053.                 Stop = STOP_Not;
  1054.  
  1055.                     /* Hang up if necessary. */
  1056.  
  1057.                 if(Start == START_Dial)
  1058.                 {
  1059.                     DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_ABORTING_TXT));
  1060.  
  1061.                         /* Hang up if necessary. */
  1062.  
  1063.                     if(DoNotHangUp)
  1064.                         DoNotHangUp = FALSE;
  1065.                     else
  1066.                         QuickHangup(DialNode);
  1067.                 }
  1068.             }
  1069.  
  1070.                 /* Start at the beginning. */
  1071.  
  1072.             if(!Done && !DialNode)
  1073.             {
  1074.                 GetCurrentSettings(DialNode = (struct DialNode *)PhoneHandle->DialList->lh_Head,&CurrentSerialConfig,&CurrentModemConfig);
  1075.  
  1076.                 LT_SetAttributes(Handle,GAD_SKIP,
  1077.                     GA_Disabled,    FALSE,
  1078.                 TAG_DONE);
  1079.  
  1080.                 LT_SetAttributes(Handle,GAD_REMOVE,
  1081.                     GA_Disabled,    FALSE,
  1082.                 TAG_DONE);
  1083.  
  1084.                 Start = START_Call;
  1085.             }
  1086.  
  1087.                 /* Are we to start a call? */
  1088.  
  1089.             if(!Done && Start == START_Call)
  1090.             {
  1091.                     /* Reset the sequence scanner, the user may have skipped
  1092.                      * the previous dial attempt causing the modem to return
  1093.                      * `NO CARRIER'. To prevent the dialer from skipping the
  1094.                      * next dial entry as well as the previous we have to
  1095.                      * flush any data pending on the serial line.
  1096.                      */
  1097.  
  1098.                 ResetDataFlowFilter();
  1099.  
  1100.                     /* Does this entry have a configuration attached? */
  1101.  
  1102.                 if(DialNode->Entry == NULL && Config->ModemConfig->DoNotSendMainModemCommands)
  1103.                     InitBuffer[0] = ExitBuffer[0] = 0;
  1104.                 else
  1105.                 {
  1106.                     LimitedStrcpy(sizeof(InitBuffer),InitBuffer,DialNode->InitCommand ? DialNode->InitCommand : CurrentModemConfig->ModemInit);
  1107.                     LimitedStrcpy(sizeof(ExitBuffer),ExitBuffer,DialNode->ExitCommand ? DialNode->ExitCommand : CurrentModemConfig->ModemExit);
  1108.                 }
  1109.  
  1110.                 LimitedStrcpy(sizeof(PrefixBuffer),PrefixBuffer,DialNode->DialPrefix ? DialNode->DialPrefix : CurrentModemConfig->DialPrefix);
  1111.                 LimitedStrcpy(sizeof(SuffixBuffer),SuffixBuffer,DialNode->DialSuffix ? DialNode->DialSuffix : CurrentModemConfig->DialSuffix);
  1112.  
  1113.                     /* Send the modem exit string before we
  1114.                      * will need to reconfigure the serial
  1115.                      * device driver.
  1116.                      */
  1117.  
  1118.                 if(ExitCommand[0])
  1119.                 {
  1120.                     if(!SendLocalModemCommand(Handle,ExitCommand,LocaleString(MSG_DIALPANEL_SENDING_MODEM_EXIT_COMMAND_TXT),LocaleString(MSG_DIALPANEL_ERROR_SENDING_MODEM_COMMAND_TXT)))
  1121.                     {
  1122.                         if(!FlowInfo.Changed)
  1123.                             ModemNotResponding = TRUE;
  1124.  
  1125.                         ErrorHasOccured = TRUE;
  1126.                         Done = TRUE;
  1127.                     }
  1128.  
  1129.                     ExitCommand[0] = 0;
  1130.                 }
  1131.  
  1132.                     /* We will need to change the serial and modem parameters
  1133.                      * in order to establish a connection.
  1134.                      */
  1135.  
  1136.                 if(!Done)
  1137.                 {
  1138.                     PutConfigEntry(Config,CurrentModemConfig,PREF_MODEM);
  1139.  
  1140.                     if(ReconfigureSerial(PanelWindow,CurrentSerialConfig) == RECONFIGURE_FAILURE)
  1141.                     {
  1142.                         WakeUp(PanelWindow,SOUND_ERROR);
  1143.  
  1144.                         ErrorHasOccured = TRUE;
  1145.                         Done = TRUE;
  1146.                     }
  1147.                 }
  1148.  
  1149.                     /* Update the ODU bits and send the modem init command, if any. */
  1150.  
  1151.                 if(!Done)
  1152.                 {
  1153.                         /* Update the ODU stuff */
  1154.  
  1155.                     if(OwnDevUnitBase && CurrentSerialConfig->ReleaseODUWhenDialing && CurrentSerialConfig->SatisfyODURequests != ODU_KEEP && !(CurrentSerialConfig->Shared && CurrentSerialConfig->NoODUIfShared))
  1156.                         ODUMask = SIG_OWNDEVUNIT;
  1157.                     else
  1158.                         ODUMask = NULL;
  1159.  
  1160.                         /* Send the modem init command. */
  1161.  
  1162.                     if(InitBuffer[0])
  1163.                     {
  1164.                         if(!SendLocalModemCommand(Handle,InitBuffer,LocaleString(MSG_DIALPANEL_SENDING_MODEM_INIT_COMMAND_TXT),LocaleString(MSG_DIALPANEL_ERROR_SENDING_MODEM_COMMAND_TXT)))
  1165.                         {
  1166.                             if(!FlowInfo.Changed)
  1167.                                 ModemNotResponding = TRUE;
  1168.  
  1169.                             ErrorHasOccured = TRUE;
  1170.                             Done = TRUE;
  1171.                         }
  1172.  
  1173.                         InitBuffer[0] = 0;
  1174.                     }
  1175.                 }
  1176.  
  1177.                     /* Get on with the rest. */
  1178.  
  1179.                 if(!Done)
  1180.                 {
  1181.                     STRPTR Comment;
  1182.  
  1183.                         /* Remember the new exit command. */
  1184.  
  1185.                     LimitedStrcpy(sizeof(ExitCommand),ExitCommand,ExitBuffer);
  1186.  
  1187.                     DialPrintBox(Handle,GAD_CALLING,0,DialNode->Node.ln_Name);
  1188.  
  1189.                         /* Show the comment, if any. */
  1190.  
  1191.                     if(DialNode->Entry && DialNode->Entry->Header->Comment[0])
  1192.                         Comment = DialNode->Entry->Header->Comment;
  1193.                     else
  1194.                         Comment = "-";
  1195.  
  1196.                     DialPrintBox(Handle,GAD_CALLING,1,Comment);
  1197.  
  1198.                         /* Display the number being called. */
  1199.  
  1200.                     DialPrintBox(Handle,GAD_CALLING,2,DialNode->Number);
  1201.  
  1202.                         /* Display the name of the service to call next. */
  1203.  
  1204.                     DialPrintBox(Handle,GAD_CALLING,3,DialNode->Node.ln_Succ->ln_Succ ? DialNode->Node.ln_Succ->ln_Name : "-");
  1205.  
  1206.                         /* Right now we're dialing. */
  1207.  
  1208.                     if(DialNode->Node.ln_Succ->ln_Succ)
  1209.                     {
  1210.                         LimitedSPrintf(sizeof(NoteText),NoteText,LocaleString(MSG_DIALER_NOTE_TXT),LocaleString(MSG_DIALPANEL_DIALING_TXT),GetListSize((struct List *)DialNode));
  1211.  
  1212.                         DialPrintBox(Handle,GAD_NOTE,0,NoteText);
  1213.                     }
  1214.                     else
  1215.                         DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_DIALING_TXT));
  1216.  
  1217.                         /* Say what we are dialing. */
  1218.  
  1219.                     Say(LocaleString(MSG_DIALPANEL_NOW_CALLING_TXT),DialNode->Node.ln_Name);
  1220.  
  1221.                         /* Pick up dial timeout and dial retries. */
  1222.  
  1223.                     DialTimeout    = CurrentModemConfig->DialTimeout;
  1224.                     DialRetries    = CurrentModemConfig->DialRetries;
  1225.  
  1226.                         /* Build the dialing command. */
  1227.  
  1228.                     LimitedStrcpy(sizeof(DialBuffer),DialBuffer,PrefixBuffer);
  1229.  
  1230.                     if(CurrentModemConfig->PBX_Mode && CurrentModemConfig->PBX_Prefix[0])
  1231.                         LimitedStrcat(sizeof(DialBuffer),DialBuffer,CurrentModemConfig->PBX_Prefix);
  1232.  
  1233.                     LimitedStrcat(sizeof(DialBuffer),DialBuffer,DialNode->Number);
  1234.                     LimitedStrcat(sizeof(DialBuffer),DialBuffer,SuffixBuffer);
  1235.  
  1236.                         /* Dial the number. */
  1237.  
  1238.                     SerialCommand(DialBuffer);
  1239.  
  1240.                         /* Now we should be dialing. */
  1241.  
  1242.                     Start = START_Dial;
  1243.  
  1244.                         /* For the sake of precision. */
  1245.  
  1246.                     GetSysTime(&LastTimeCheck);
  1247.                 }
  1248.             }
  1249.  
  1250.                 /* Are we to skip the current assignment? */
  1251.  
  1252.             if(!Done && Stop == STOP_Skip)
  1253.             {
  1254.                 Stop = STOP_Not;
  1255.  
  1256.                 switch(Start)
  1257.                 {
  1258.                         /* Are we currently dialing? */
  1259.  
  1260.                     case START_Dial:
  1261.  
  1262.                             /* Hang up if necessary. */
  1263.  
  1264.                         if(DoNotHangUp)
  1265.                             DoNotHangUp = FALSE;
  1266.                         else
  1267.                             QuickHangup(DialNode);
  1268.  
  1269.                             /* Is this one the last entry? */
  1270.  
  1271.                         if(DialNode->Node.ln_Succ->ln_Succ)
  1272.                         {
  1273.                                 /* There is still another entry. */
  1274.  
  1275.                             GetCurrentSettings(DialNode = (struct DialNode *)DialNode->Node.ln_Succ,&CurrentSerialConfig,&CurrentModemConfig);
  1276.  
  1277.                                 /* Check if we should wait before we fire off another dial command. */
  1278.  
  1279.                             if(CurrentModemConfig->InterDialDelay)
  1280.                             {
  1281.                                     /* Wait until the inter-dial delay has elapsed. */
  1282.  
  1283.                                 RedialTimeout = CurrentModemConfig->InterDialDelay;
  1284.  
  1285.                                 DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_WAITING_TO_CALL_TXT));
  1286.  
  1287.                                 Say(LocaleString(MSG_DIALPANEL_WAITING_TXT));
  1288.  
  1289.                                     /* No entry is currently being called. */
  1290.  
  1291.                                 DialPrintBox(Handle,GAD_CALLING,0,"-");
  1292.                                 DialPrintBox(Handle,GAD_CALLING,1,"-");
  1293.                                 DialPrintBox(Handle,GAD_CALLING,2,"-");
  1294.  
  1295.                                 LT_SetAttributes(Handle,GAD_REMOVE,
  1296.                                     GA_Disabled,    TRUE,
  1297.                                 TAG_DONE);
  1298.  
  1299.                                     /* Display name of entry to call next. */
  1300.  
  1301.                                 DialPrintBox(Handle,GAD_CALLING,3,DialNode->Node.ln_Name);
  1302.  
  1303.                                 Start = START_Wait;
  1304.  
  1305.                                     /* For the sake of precision. */
  1306.  
  1307.                                 GetSysTime(&LastTimeCheck);
  1308.                             }
  1309.                             else
  1310.                                 Start = START_Call;
  1311.                         }
  1312.                         else
  1313.                         {
  1314.                                 /* Yet another dial attempt coming up. */
  1315.  
  1316.                             DialAttempt++;
  1317.  
  1318.                                 /* Is this one the last dial
  1319.                                  * attempt to be made?
  1320.                                  */
  1321.  
  1322.                             if(DialAttempt >= DialRetries && DialRetries >= 0)
  1323.                             {
  1324.                                 DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_MAXIMUM_NUMBER_OF_DIAL_RETRIES_TXT));
  1325.  
  1326.                                 WakeUp(PanelWindow,SOUND_BELL);
  1327.  
  1328.                                 DelayTime(2,0);
  1329.  
  1330.                                 Say(LocaleString(MSG_DIALPANEL_MAXIMUM_NUMBER_OF_DIAL_RETRIES_TXT));
  1331.  
  1332.                                 Done = TRUE;
  1333.                             }
  1334.                             else
  1335.                             {
  1336.                                 LONG InterDialDelay;
  1337.  
  1338.                                     /* Get the first list entry. */
  1339.  
  1340.                                 GetCurrentSettings(DialNode = (struct DialNode *)PhoneHandle->DialList->lh_Head,&CurrentSerialConfig,&CurrentModemConfig);
  1341.  
  1342.                                     /* Get the redial delay. */
  1343.  
  1344.                                 RedialTimeout    = CurrentModemConfig->RedialDelay;
  1345.                                 InterDialDelay    = CurrentModemConfig->InterDialDelay;
  1346.  
  1347.                                     /* Check if the inter-dial delay is larger than
  1348.                                      * the redial delay. If so, use the inter-dial delay.
  1349.                                      */
  1350.  
  1351.                                 if(InterDialDelay > RedialTimeout)
  1352.                                     RedialTimeout = InterDialDelay;
  1353.  
  1354.                                     /* No redial delay? Restart dialing... */
  1355.  
  1356.                                 if(!RedialTimeout)
  1357.                                 {
  1358.                                     Start = START_Call;
  1359.  
  1360.                                     DelayTime(1,0);
  1361.                                 }
  1362.                                 else
  1363.                                 {
  1364.                                         /* Go into redial delay. */
  1365.  
  1366.                                     DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_REDIAL_DELAY_TXT));
  1367.  
  1368.                                     Say(LocaleString(MSG_DIALPANEL_WAITING_TXT));
  1369.  
  1370.                                         /* No entry is currently being called. */
  1371.  
  1372.                                     DialPrintBox(Handle,GAD_CALLING,0,"-");
  1373.                                     DialPrintBox(Handle,GAD_CALLING,1,"-");
  1374.                                     DialPrintBox(Handle,GAD_CALLING,2,"-");
  1375.  
  1376.                                     LT_SetAttributes(Handle,GAD_REMOVE,
  1377.                                         GA_Disabled,    TRUE,
  1378.                                     TAG_DONE);
  1379.  
  1380.                                         /* Display name of entry to call next. */
  1381.  
  1382.                                     DialPrintBox(Handle,GAD_CALLING,3,DialNode->Node.ln_Name);
  1383.  
  1384.                                     Start = START_Wait;
  1385.  
  1386.                                         /* For the sake of precision. */
  1387.  
  1388.                                     GetSysTime(&LastTimeCheck);
  1389.                                 }
  1390.                             }
  1391.                         }
  1392.  
  1393.                         break;
  1394.  
  1395.                         /* Stop waiting. */
  1396.  
  1397.                     case START_Wait:
  1398.  
  1399.                         if(Start == START_Wait)
  1400.                         {
  1401.                             LT_SetAttributes(Handle,GAD_REMOVE,
  1402.                                 GA_Disabled,    FALSE,
  1403.                             TAG_DONE);
  1404.  
  1405.                             Start = START_Call;
  1406.                         }
  1407.  
  1408.                         break;
  1409.                 }
  1410.             }
  1411.  
  1412.                 /* Take care of serial input. */
  1413.  
  1414.             if(!Done)
  1415.                 RunJob(SerialJob);
  1416.  
  1417.                 /* Any news from the modem? */
  1418.  
  1419.             if(!Done && FlowInfo.Changed)
  1420.             {
  1421.                     /* Current number is busy. */
  1422.  
  1423.                 if(FlowInfo.Busy || (FlowInfo.NoCarrier && CurrentModemConfig->NoCarrierIsBusy))
  1424.                 {
  1425.                     if(!Done && Start == START_Dial)
  1426.                     {
  1427.                         DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_LINE_IS_BUSY_TXT));
  1428.  
  1429.                         Say(LocaleString(MSG_DIALPANEL_LINE_IS_BUSY_TXT));
  1430.  
  1431.                         DelayTime(1,0);
  1432.  
  1433.                         Stop = STOP_Skip;
  1434.  
  1435.                         DoNotHangUp = TRUE;
  1436.                     }
  1437.  
  1438.                     ResetDataFlowFilter();
  1439.                 }
  1440.  
  1441.                     /* Line does not feature a dialtone. */
  1442.  
  1443.                 if(FlowInfo.NoDialTone)
  1444.                 {
  1445.                     if(!Done && Start == START_Dial)
  1446.                     {
  1447.                         DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_NO_DIALTONE_TXT));
  1448.  
  1449.                         WakeUp(PanelWindow,SOUND_ERROR);
  1450.  
  1451.                         Say(LocaleString(MSG_DIALPANEL_NO_DIALTONE_TXT));
  1452.  
  1453.                         ErrorHasOccured = TRUE;
  1454.                         Done = TRUE;
  1455.                     }
  1456.  
  1457.                     ResetDataFlowFilter();
  1458.                 }
  1459.  
  1460.                     /* Somebody tries to call us. */
  1461.  
  1462.                 if(FlowInfo.Ring)
  1463.                 {
  1464.                     if(!Done)
  1465.                     {
  1466.                         DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_GLOBAL_INCOMING_CALL_TXT));
  1467.  
  1468.                         WakeUp(PanelWindow,SOUND_RING);
  1469.  
  1470.                         Say(LocaleString(MSG_GLOBAL_INCOMING_CALL_TXT));
  1471.  
  1472.                         ErrorHasOccured = TRUE;
  1473.                         Done = TRUE;
  1474.                     }
  1475.  
  1476.                     ResetDataFlowFilter();
  1477.                 }
  1478.  
  1479.                     /* Somebody's talking. */
  1480.  
  1481.                 if(FlowInfo.Voice)
  1482.                 {
  1483.                     if(!Done)
  1484.                     {
  1485.                         DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_INCOMING_VOICE_CALL_TXT));
  1486.  
  1487.                         WakeUp(PanelWindow,SOUND_VOICE);
  1488.  
  1489.                         Say(LocaleString(MSG_DIALPANEL_INCOMING_VOICE_CALL_TXT));
  1490.  
  1491.                         ErrorHasOccured = TRUE;
  1492.                         Done = TRUE;
  1493.                     }
  1494.  
  1495.                     ResetDataFlowFilter();
  1496.                 }
  1497.  
  1498.                     /* We got a connect. */
  1499.  
  1500.                 if(FlowInfo.Connect)
  1501.                 {
  1502.                     if(!Done && Start == START_Dial)
  1503.                     {
  1504.                             /* Make the connection. */
  1505.  
  1506.                         Connect(PhoneHandle,DialNode);
  1507.  
  1508.                         Done = TRUE;
  1509.  
  1510.                             /* Wake the user up. */
  1511.  
  1512.                         if(BaudBuffer[0])
  1513.                         {
  1514.                             DialPrintBox(Handle,GAD_NOTE,0,"CONNECT %s",BaudBuffer);
  1515.  
  1516.                             WakeUp(PanelWindow,SOUND_CONNECT);
  1517.  
  1518.                             DelayTime(2,0);
  1519.  
  1520.                                 /* Install new baud rate if desired. */
  1521.  
  1522.                             if(Config->ModemConfig->ConnectAutoBaud && DTERate > 110)
  1523.                             {
  1524.                                 Config->SerialConfig->BaudRate = DTERate;
  1525.  
  1526.                                 ReconfigureSerial(PanelWindow,NULL);
  1527.                             }
  1528.                         }
  1529.                         else
  1530.                         {
  1531.                             DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_CONNECTION_ESTABLISHED_TXT));
  1532.  
  1533.                             WakeUp(PanelWindow,SOUND_CONNECT);
  1534.                         }
  1535.  
  1536.                         Say(LocaleString(MSG_DIALPANEL_CONNECTION_ESTABLISHED_TXT));
  1537.                     }
  1538.  
  1539.                     ResetDataFlowFilter();
  1540.                 }
  1541.  
  1542.                     /* Looks like an error. */
  1543.  
  1544.                 if(FlowInfo.Error)
  1545.                 {
  1546.                     if(!Done && Start == START_Dial)
  1547.                     {
  1548.                         DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_ERROR_SENDING_MODEM_COMMAND_TXT));
  1549.  
  1550.                         WakeUp(PanelWindow,SOUND_ERROR);
  1551.  
  1552.                         ErrorHasOccured = TRUE;
  1553.                         Done = TRUE;
  1554.                     }
  1555.  
  1556.                     ResetDataFlowFilter();
  1557.                 }
  1558.  
  1559.                     /* In any other case, reset the scanner. */
  1560.  
  1561.                 ResetDataFlowFilter();
  1562.             }
  1563.  
  1564.                 /* If nothing special's up... */
  1565.  
  1566.             if(!Done && Stop == STOP_Not && Start != START_Call)
  1567.             {
  1568.                 struct timeval Now,Then;
  1569.  
  1570.                     /* Give a brief report. */
  1571.  
  1572.                 switch(Start)
  1573.                 {
  1574.                     case START_Dial:
  1575.  
  1576.                         DialPrintBox(Handle,GAD_TIME,0,"%2ld:%02ld",DialTimeout / 60,DialTimeout % 60);
  1577.                         DialPrintBox(Handle,GAD_TIME,1,LocaleString(DialRetries < 0 ? MSG_DIAL_RETRIES_UNLIMITED_TXT : MSG_DIALPANEL_ATTEMPT_OF_TXT),DialAttempt + 1,DialRetries);
  1578.  
  1579.                         break;
  1580.  
  1581.                     case START_Wait:
  1582.  
  1583.                         DialPrintBox(Handle,GAD_TIME,0,"%2ld:%02ld",RedialTimeout / 60,RedialTimeout % 60);
  1584.                         break;
  1585.                 }
  1586.  
  1587.                     /* Wait a second or until something interesting happens. */
  1588.  
  1589.                 StartTime(1,0);
  1590.  
  1591.                 Signals = Wait(SIG_TIMER | SIG_BREAK | SIG_SKIP | ODUMask | WindowMask);
  1592.  
  1593.                 StopTime();
  1594.  
  1595.                     /* Get the current time. */
  1596.  
  1597.                 GetSysTime(&Now);
  1598.  
  1599.                     /* Check if the current time is "later" than the last time check.
  1600.                      * This is to avoid embarrassing situations such as could take
  1601.                      * place if the the user resets the operating system time.
  1602.                      */
  1603.  
  1604.                 if(-CmpTime(&Now,&LastTimeCheck) >= 0)
  1605.                 {
  1606.                     CopyMem(&Now,&Then,sizeof(struct timeval));
  1607.                     SubTime(&Now,&LastTimeCheck);
  1608.                 }
  1609.                 else
  1610.                 {
  1611.                     CopyMem(&Now,&LastTimeCheck,sizeof(struct timeval));
  1612.                     Now.tv_secs = 0;
  1613.                 }
  1614.  
  1615.                     /* The following instructions are executed as time passes by. */
  1616.  
  1617.                 if(Now.tv_secs > 0)
  1618.                 {
  1619.                     LONG Seconds = Now.tv_secs;
  1620.  
  1621.                         /* Remember the last time we went through. */
  1622.  
  1623.                     CopyMem(&Then,&LastTimeCheck,sizeof(struct timeval));
  1624.  
  1625.                     switch(Start)
  1626.                     {
  1627.                             /* Are we dialing? */
  1628.  
  1629.                         case START_Dial:
  1630.  
  1631.                             if(DialTimeout > Seconds)
  1632.                                 DialTimeout -= Seconds;
  1633.                             else
  1634.                             {
  1635.                                 DialTimeout = 0;
  1636.  
  1637.                                     /* The dial timeout has elapsed without
  1638.                                      * a connection being made.
  1639.                                      */
  1640.  
  1641.                                 Stop = STOP_Skip;
  1642.  
  1643.                                 DialPrintBox(Handle,GAD_NOTE,0,LocaleString(MSG_DIALPANEL_DIAL_ATTEMPT_TIMEOUT_TXT));
  1644.                             }
  1645.  
  1646.                             break;
  1647.  
  1648.                             /* Are we waiting? */
  1649.  
  1650.                         case START_Wait:
  1651.  
  1652.                             if(RedialTimeout > Seconds)
  1653.                                 RedialTimeout -= Seconds;
  1654.                             else
  1655.                             {
  1656.                                 RedialTimeout = 0;
  1657.  
  1658.                                     /* The redial delay has elapsed,
  1659.                                      * start dialing again.
  1660.                                      */
  1661.  
  1662.                                 Stop = STOP_Skip;
  1663.                             }
  1664.  
  1665.                             break;
  1666.                     }
  1667.                 }
  1668.             }
  1669.         }
  1670.         while(!Done);
  1671.  
  1672.             /* Reset the status */
  1673.  
  1674.         PopStatus();
  1675.  
  1676.             /* Are we online or not? */
  1677.  
  1678.         if(!Online)
  1679.         {
  1680.             BOOL SendCommands;
  1681.  
  1682.                 /* If the modem is not responding anyway, don't bother
  1683.                  * sending any commands.
  1684.                  */
  1685.  
  1686.             SendCommands = (BOOL)(ModemNotResponding == FALSE);
  1687.  
  1688.                 /* Is the serial setup different? */
  1689.  
  1690.             if(CompareConfigEntries(Config->SerialConfig,OriginalSerialConfig,PREF_SERIAL))
  1691.             {
  1692.                     /* Set up the old serial configuration. */
  1693.  
  1694.                 if(ReconfigureSerial(PanelWindow,OriginalSerialConfig) == RECONFIGURE_FAILURE)
  1695.                     SendCommands = FALSE;
  1696.             }
  1697.  
  1698.                 /* Put back the original modem settings. */
  1699.  
  1700.             PutConfigEntry(Config,OriginalModemConfig,PREF_MODEM);
  1701.  
  1702.             if(SendCommands)
  1703.             {
  1704.                     /* Send the exit command if necessary. */
  1705.  
  1706.                 if(ExitCommand[0])
  1707.                 {
  1708.                     if(!SendLocalModemCommand(Handle,ExitCommand,LocaleString(MSG_DIALPANEL_SENDING_MODEM_EXIT_COMMAND_TXT),LocaleString(MSG_DIALPANEL_ERROR_SENDING_MODEM_COMMAND_TXT)))
  1709.                         ErrorHasOccured = TRUE;
  1710.                 }
  1711.  
  1712.                     /* Take care of the init command if necessary. */
  1713.  
  1714.                 if(Config->ModemConfig->ModemInit[0] && !ErrorHasOccured)
  1715.                 {
  1716.                     if(!SendLocalModemCommand(Handle,Config->ModemConfig->ModemInit,LocaleString(MSG_DIALPANEL_SENDING_MODEM_INIT_COMMAND_TXT),LocaleString(MSG_DIALPANEL_ERROR_SENDING_MODEM_COMMAND_TXT)))
  1717.                         ErrorHasOccured = TRUE;
  1718.                 }
  1719.             }
  1720.         }
  1721.  
  1722.             /* Make sure the error gets displayed. */
  1723.  
  1724.         if(ErrorHasOccured && !ReleaseSerialDevice)
  1725.         {
  1726.             LONG i;
  1727.  
  1728.             for(i = GAD_SKIP ; i <= GAD_REMOVE ; i++)
  1729.                 LT_SetAttributes(Handle,i,GA_Disabled,TRUE,TAG_DONE);
  1730.  
  1731.             Done = FALSE;
  1732.  
  1733.             do
  1734.             {
  1735.                 if(Wait(WindowMask | SIG_BREAK) & SIG_BREAK)
  1736.                     break;
  1737.                 else
  1738.                 {
  1739.                     struct IntuiMessage    *Message;
  1740.  
  1741.                     while(Message = LT_GetIMsg(Handle))
  1742.                     {
  1743.                         if(Message->Class == IDCMP_CLOSEWINDOW || Message->Class == IDCMP_GADGETUP)
  1744.                             Done = TRUE;
  1745.  
  1746.                         LT_ReplyIMsg(Message);
  1747.                     }
  1748.                 }
  1749.             }
  1750.             while(!Done);
  1751.         }
  1752.  
  1753.             /* Put back the old routine if necessary */
  1754.  
  1755.         RestoreSendLine(SendLineDial,OriginalSendLine);
  1756.  
  1757.         PopWindow();
  1758.  
  1759.         LT_DeleteHandle(Handle);
  1760.  
  1761.             /* Reset the scanner. */
  1762.  
  1763.         ResetDataFlowFilter();
  1764.  
  1765.             /* We are done now, restart echoing serial input. */
  1766.  
  1767.         SetConsoleQuiet(OldQuietSettings);
  1768.  
  1769.             /* Reset the display if necessary. */
  1770.  
  1771.         if(ResetDisplay)
  1772.         {
  1773.             if(!DisplayReset())
  1774.             {
  1775.                 FreeVecPooled(OriginalSerialConfig);
  1776.                 OriginalSerialConfig = NULL;
  1777.  
  1778.                 FreeVecPooled(OriginalModemConfig);
  1779.                 OriginalModemConfig = NULL;
  1780.  
  1781.                 return(FALSE);
  1782.             }
  1783.         }
  1784.  
  1785.             /* Handle online jobs. */
  1786.  
  1787.         SetDialMenu(Online == FALSE);
  1788.  
  1789.         if(Online)
  1790.         {
  1791.                 /* Send the startup macro if necessary. */
  1792.  
  1793.             if(SendStartup && !SkipLoginMacro)
  1794.             {
  1795.                 if(Config->CommandConfig->LoginMacro[0])
  1796.                     SerialCommand(Config->CommandConfig->LoginMacro);
  1797.  
  1798.                 if(Config->CommandConfig->StartupMacro[0])
  1799.                     SerialCommand(Config->CommandConfig->StartupMacro);
  1800.  
  1801.                 SendStartup = FALSE;
  1802.             }
  1803.  
  1804.                 /* Take care of the recording feature. */
  1805.  
  1806.             if(RecordOnConnection)
  1807.             {
  1808.                 if(CreateRecord(CurrentBBSName[0] ? CurrentBBSName : CurrentBBSNumber))
  1809.                 {
  1810.                     RememberResetOutput();
  1811.                     RememberResetInput();
  1812.  
  1813.                     RememberOutput    = TRUE;
  1814.  
  1815.                     Recording        = TRUE;
  1816.                     RecordingLine    = FALSE;
  1817.  
  1818.                     PushStatus(STATUS_RECORDING);
  1819.  
  1820.                     OnItem(MEN_RECORD_LINE);
  1821.  
  1822.                     CheckItem(MEN_RECORD,TRUE);
  1823.                     CheckItem(MEN_RECORD_LINE,FALSE);
  1824.                 }
  1825.             }
  1826.         }
  1827.     }
  1828.  
  1829.         /* Reply to the messages that started the
  1830.          * dialing process.
  1831.          */
  1832.  
  1833.     DispatchRexxDialMsgList(Online);
  1834.  
  1835.         /* Release the serial device driver if necessary. */
  1836.  
  1837.     if(ReleaseSerialDevice)
  1838.         RunJob(OwnDevUnitJob);
  1839.  
  1840.         /* Release the backup data. */
  1841.  
  1842.     FreeVecPooled(OriginalSerialConfig);
  1843.     OriginalSerialConfig = NULL;
  1844.  
  1845.     FreeVecPooled(OriginalModemConfig);
  1846.     OriginalModemConfig = NULL;
  1847.  
  1848.         /* Exit and tell the caller if control should pass
  1849.          * back to the phonebook control panel.
  1850.          */
  1851.  
  1852.     return(ReturnToPhonebook);
  1853. }
  1854.